<template xmlns="http://www.w3.org/1999/html">
  <div class="app-container">
    <el-form :model="queryParams" ref="queryForm" :inline="true" v-show="showSearch" label-width="110px">
      <el-form-item label="用户ID" prop="userId">
        <el-input v-model="queryParams.userId" placeholder="请输入用户ID" clearable size="small"
          @keyup.enter.native="handleQuery" />
      </el-form-item>
      <el-form-item label="推荐人信息" prop="payeeUserId">
        <el-input v-model="queryParams.payeeUserId" placeholder="请输入推荐人信息" clearable size="small"
          @keyup.enter.native="handleQuery" />
      </el-form-item>
      <!-- <el-form-item label="佣金类型" prop="auditStatus">
        <el-select
          v-model="queryParams.auditStatus"
          placeholder="请选择状态"
          clearable
          size="small"
          style="width: 240px"
        >
          <el-option
            v-for="item in auditStatusOptions"
            :key="item.value"
            :label="item.label"
            :value="item.value"
          />
        </el-select>
      </el-form-item> -->
      <el-form-item label="申请日期">
        <el-date-picker v-model="dateRange1" size="small" style="width: 240px" value-format="yyyy-MM-dd"
          type="daterange" range-separator="-" start-placeholder="开始日期" end-placeholder="结束日期"></el-date-picker>
      </el-form-item>
      <!-- <el-form-item label="审核日期">
        <el-date-picker
          v-model="dateRange2"
          size="small"
          style="width: 240px"
          value-format="yyyy-MM-dd"
          type="daterange"
          range-separator="-"
          start-placeholder="开始日期"
          end-placeholder="结束日期"
        ></el-date-picker>
      </el-form-item> -->
      <el-form-item>
        <el-button type="cyan" icon="el-icon-search" size="mini" @click="handleQuery">搜索
        </el-button>
        <el-button icon="el-icon-refresh" size="mini" @click="resetQuery">重置
        </el-button>
      </el-form-item>
    </el-form>

    <div class="table_title">
      <span>列表数据</span>
      <el-button icon="el-icon-edit" size="mini" @click="handleCharge">手续费设置
      </el-button>
      <p>转账手续费 {{ serviceCharge }}% 转账积分点{{ integralCharge }}%</p>
    </div>
    <el-table v-loading="loading" :data="withdrawList" @selection-change="handleSelectionChange">
      <el-table-column label="申请人" align="center" prop="userId" />
      <el-table-column label="申请时间" align="center" prop="createTime" />
      <el-table-column label="转账金额" align="center" prop="money" />
      <el-table-column label="手续费" align="center" prop="serviceCharge" />
      <el-table-column label="实际到账" align="center" prop="actualAmount" />
      <el-table-column label="接收人信息" align="center">
        <template slot-scope="scope">
          <span v-if="scope.row.memberInfo">账号(id): {{ scope.row.memberInfo.userId }}
          </span>
          <br />
          <span v-if="scope.row.memberInfo">电话:{{ scope.row.phone }} </span>
        </template>
      </el-table-column>
      <el-table-column label="状态" align="center" prop="auditTime">
        <template slot-scope="scope">
          <!-- 数据库状态未改 -->
          <span>{{
            scope.row.status == 0
              ? "已到账"
              : scope.row.status == 1
              ? "已到账"
              : ""
          }}</span>
        </template>
      </el-table-column>
    </el-table>

    <pagination v-show="total > 0" :total="total" :page.sync="querypage.current" :limit.sync="querypage.size"
      @pagination="getList" />

    <el-dialog :title="title" :visible.sync="open" width="500px" append-to-body>
      <el-form ref="form" :model="form" label-width="123px">
        <el-form-item label="转账手续费" prop="commission">
          <el-input-number v-model.number="form.commission" :min="1" :max="100" /><span>%</span>
        </el-form-item>
        <el-form-item label="转账积分点" prop="integral">
          <el-input-number v-model.number="form.integral" :min="1" :max="100" /><span>%</span>
        </el-form-item>
      </el-form>
      <div slot="footer" class="dialog-footer">
        <el-button type="primary" @click="submitForm">确 定</el-button>
        <el-button @click="cancel">取 消</el-button>
      </div>
    </el-dialog>

    <!-- 通过提现 -->
    <el-dialog title="审核通过" :visible.sync="tgVisible" width="25%">
      <!-- :before-close="handleClose" -->
      <div class="txdialog-span">
        <span>确认通过该用户的转账申请？</span>
        <br />
        <div class="txdialog">
          <span>转账用户(id)：<span class="red">{{ selectrow.userId }}</span></span>
          <span>打款金额：<span class="red">{{ selectrow.cashMoney }}</span></span>
        </div>
      </div>

      <span slot="footer" class="dialog-footer">
        <el-button @click="tgVisible = false">取 消</el-button>
        <el-button type="primary" @click="tgVisible = false">确 定</el-button>
      </span>
    </el-dialog>

    <!-- 驳回提现 -->
    <el-dialog title="审核驳回" :visible.sync="bhVisible" width="25%">
      <!-- :before-close="handleClose" -->
      <div class="txdialog-beiz">
        <span>备注</span>
        <!-- <el-input
          type="text"
          placeholder="请输入内容"
          v-model="bhtext"
          maxlength="50"
          show-word-limit
        >
        </el-input> -->
        <el-input type="textarea" placeholder="请输入内容" v-model="textaretext" autosize maxlength="50" show-word-limit>
        </el-input>
      </div>

      <span slot="footer" class="dialog-footer">
        <el-button @click="bhVisible = false">取 消</el-button>
        <el-button type="primary" @click="bhVisible = false">确 定</el-button>
      </span>
    </el-dialog>
  </div>
</template>

<script>
import {
  selTransferRecords,
  upTransferRecord,
  selTransferRecord,
} from "@/api/admin/finance";

export default {
  name: "UserWithdraw",
  data() {
    return {
      // 遮罩层
      loading: true,
      // 选中数组
      ids: [],
      // 非单个禁用
      single: true,
      // 非多个禁用
      multiple: true,
      // 显示搜索条件
      showSearch: true,
      // 总条数
      total: 0,
      // 任务详情表格数据
      withdrawList: [],
      // 弹出层标题
      title: "",
      //查询日期
      // 是否显示弹出层
      open: false,
      tgVisible: false,
      bhVisible: false,
      bhtext: "",
      textaretext: "",
      selectrow: {},
      // 查询参数
      querypage: {
        current: 1,
        size: 10,
      },
      queryParams: {
        userId: "",
        payeeUserId: "",
        applyForBeginTime: "",
        applyForEndTime: "",
      },
      dateRange1: [],
      dateRange2: [],
      auditStatusOptions: [
        {
          value: 1,
          label: "待审核",
        },
        {
          value: 2,
          label: "已到账",
        },
        {
          value: 3,
          label: "已驳回",
        },
        {
          value: 4,
          label: "打款失败",
        },
        {
          value: 5,
          label: "已撤销",
        },
      ],
      form: {},
      serviceCharge: "",
      integralCharge: "",
    };
  },
  created() {
    this.getList();
    this.CommissionProportionfun();
  },
  methods: {
    CommissionProportionfun() {
      selTransferRecord().then((res) => {
        this.serviceCharge = res.data.transferAccounts;
        this.integralCharge = res.data.integralAccounts;
      });
    },
    getList() {
      this.loading = true;
      if (null != this.dateRange1 && "" != this.dateRange1) {
        this.queryParams.beginTime1 = this.dateRange1[0] + " 00:00:00";
        this.queryParams.endTime1 = this.dateRange1[1] + " 23:59:59";
      }
      if (null != this.dateRange2 && "" != this.dateRange2) {
        this.queryParams.beginTime2 = this.dateRange2[0] + " 00:00:00";
        this.queryParams.endTime2 = this.dateRange2[1] + " 23:59:59";
      }

      selTransferRecords(this.queryParams, this.querypage).then((response) => {
        this.withdrawList = response.data.records;
        this.total = response.data.total;
        this.loading = false;
        //console.log(this.withdrawList);
      });
    },
    /** 搜索按钮操作 */
    handleQuery() {
      this.querypage.current = 1;
      this.queryParams.applyForBeginTime =
        this.dateRange1 && this.dateRange1[0]
          ? this.dateRange1[0] + " 00:00:00"
          : "";
      this.queryParams.applyForEndTime =
        this.dateRange1 && this.dateRange1[1]
          ? this.dateRange1[1] + " 23:59:59"
          : "";
      this.getList();
      // this.getTotal();
    },
    /** 重置按钮操作 */
    resetQuery() {
      // this.resetForm("queryForm");
      this.resetForm("queryParams");
      this.queryParams.applyForBeginTime = "";
      this.queryParams.applyForEndTime = "";
      this.dateRange1 = [];
      this.dateRange2 = [];
      this.handleQuery();
    },
    // 多选框选中数据
    handleSelectionChange(selection) {
      this.ids = selection.map((item) => item.id);
      this.single = selection.length !== 1;
      this.multiple = !selection.length;
    },
    audittgfun(row, auditStatus) {
      let _self = this;
      this.selectrow = row;
      this.tgVisible = true;
      // _self.open = true;
      // _self.auditForm = {};
      // _self.auditForm = { goodsId: row.goodsId, auditStatus: auditStatus };
      // let text = "";
      // if (auditStatus === -1) {
      //   text = "拒绝";
      // } else {
      //   text = "通过";
      // }
      // this.$confirm(
      //   "确定审核" + "(id:" + row.userId + ")" + "该提现记录吗?",
      //   "警告",
      //   {
      //     confirmButtonText: "确定",
      //     cancelButtonText: "取消",
      //     type: "warning",
      //   }
      // )
      //   .then(function () {
      //     return auditWithdraw(_self.auditForm);
      //   })
      //   .then(() => {
      //     this.msgSuccess("审核成功");
      //     this.getList();
      //     this.reload();
      //   })
      //   .catch(function () {});
    },
    audit(row, auditStatus) {
      this.bhVisible = true;
      // let _self = this;
      // _self.open = true;
      // _self.auditForm = {};
      // _self.auditForm = { goodsId: row.goodsId, auditStatus: auditStatus };
      // let text = "";
      // if (auditStatus === -1) {
      //   text = "拒绝";
      // } else {
      //   text = "通过";
      // }
      // this.$confirm("确定审核" + text + "该提现记录吗?", "警告", {
      //   confirmButtonText: "确定",
      //   cancelButtonText: "取消",
      //   type: "warning",
      // })
      //   .then(function () {
      //     return auditWithdraw(_self.auditForm);
      //   })
      //   .then(() => {
      //     this.msgSuccess("审核成功");
      //     this.getList();
      //     this.reload();
      //   })
      //   .catch(function () {});
    },
    handleCharge() {
      this.title = "手续费设置";
      this.reset();
      // getServiceChargeInfo(this.form).then(response => {
      //   if (response.code === 200) {
      //     this.form = response.data;
      //   }
      // });
      this.form = {
        id: 1,
        commission: this.serviceCharge,
        integral: this.integralCharge,
      };
      this.open = true;
    },
    // 取消按钮
    cancel() {
      this.open = false;
      this.reset();
    },
    // 表单重置
    reset() {
      this.form = {};
      this.resetForm("form");
    },
    /** 提交按钮 */
    submitForm() {
      this.$refs["form"].validate((valid) => {
        if (valid) {
          if (this.form.id != null) {
            upTransferRecord({
              transferAccounts: this.form.commission,
              integralAccounts: this.form.integral,
            }).then((response) => {
              if (response.code === 200) {
                this.serviceCharge = this.form.commission;
                this.integralCharge = this.form.integral;
                this.msgSuccess("修改成功");
                this.open = false;
                this.getList();
              }
            });
          }
        }
      });
    },
  },
};
</script>
<style scoped lang="scss">
.visible {
  .top {
    background: #d7d7d7;
    display: flex;
    justify-content: center;
    align-items: center;
    padding: 15px;
    font-weight: 900;
    font-size: 18px;
    color: #000000;
  }

  > p {
    display: flex;
    padding: 20px;

    > span {
      margin-right: 20px;

      > span {
        color: #7f7f7f;
      }
    }
  }
}

.status_color {
  color: #7db603;
}

.status_colorRed {
  color: #d9001b;
}

.el-tag {
  padding: 58px;
  font-size: 20px;
}
.txdialog {
  text-align: center;
  margin-top: 40px;
  span {
    margin-right: 40px;
  }
}
.txdialog-beiz {
  display: flex;
  span {
    white-space: normal;
    white-space: nowrap;
    margin-right: 10px;
  }
}
.txdialog-span {
  width: 100%;
  text-align: center;
}
.red {
  color: red;
}
.table_title {
  display: flex;
  text-align: left;
  align-items: center;
  span {
    font-size: 22px;
    font-weight: bold;
    margin-right: 20px;
  }
  p {
    font-size: 12px;
    margin-left: 10px;
  }
}
</style>
